package com.hao.product.app.aop;

import com.hao.common.code.ErrorCode;
import com.hao.common.execption.BusinessException;
import com.hao.product.app.annotation.LoginCheck;
import com.hao.product.app.feign.UserFeign;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * @author haoge
 * @version 1.0
 * @date 2023/5/23 14:36
 */
@Aspect
@Component
public class LoginInterceptor {
    @Resource
    private UserFeign userFeign;

    @Around ("@annotation(loginCheck)")
    public Object doInterceptor(ProceedingJoinPoint joinPoint, LoginCheck loginCheck) throws Throwable {
        Long login = userFeign.isLogin();
        if (login == null) {
            throw new BusinessException(ErrorCode.NO_AUTH_ERROR, "未登录");
        }
        return joinPoint.proceed();
    }
}
